<?php

namespace App\Admin\Controllers\Config;

use App\Admin\Repositories\ComputeSet;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class ComputeSetController extends AdminController
{

    public function index(Content $content)
    {
        return $content
            ->title('收益计算器')
            ->description($this->description()['index'] ?? trans('admin.list'))
            ->body($this->grid());
    }
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new ComputeSet(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('type');
            $grid->column('phs');
            $grid->column('phs_yun');
            $grid->column('work_num');
            $grid->column('work_price');
            $grid->column('fil_price');
            $grid->column('work_get');
            $grid->column('phs_ratio');
            $grid->column('tech_fee');
            $grid->column('custody_fee');
            $grid->column('period_day');
            $grid->column('created_at');
            $grid->model()->orderBy("id",'desc');
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ComputeSet(), function (Show $show) {
            $show->field('id');
            $show->field('type');
            $show->field('phs');
            $show->field('phs_yun');
            $show->field('work_num');
            $show->field('work_price');
            $show->field('fil_price');
            $show->field('work_get');
            $show->field('phs_ratio');
            $show->field('tech_fee');
            $show->field('custody_fee');
            $show->field('period_day');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ComputeSet(), function (Form $form) {
            $form->display('id');
            $form->select('type');
            $form->text('phs');
            $form->text('phs_yun');
            $form->text('work_num');
            $form->text('work_price');
            $form->text('fil_price');
            $form->text('work_get');
            $form->text('phs_ratio');
            $form->text('tech_fee');
            $form->text('custody_fee');
            $form->text('period_day');
        });
    }
}
